package com.huluobo.higt4demo1911.utils.gift.impl;

import android.animation.ObjectAnimator;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;

import com.blankj.utilcode.util.SizeUtils;
import com.huluobo.higt4demo1911.R;
import com.huluobo.higt4demo1911.utils.gift.GiftBean;

/**
 * Created by lc on 2022/4/29.
 * 具体礼物的实现
 */
public class GiftDefView extends LinearLayout implements IGiftView, IAnim {

    public GiftDefView(Context context) {
        super(context);
    }

    public GiftDefView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void inAnim() {
        ObjectAnimator animator = ObjectAnimator.ofFloat(this, "TranslationX", -SizeUtils.dp2px(250), 0);
        animator.setInterpolator(new LinearInterpolator());
        animator.setDuration(200);
        animator.start();
    }

    @Override
    public void outAnim() {
        ObjectAnimator animator = ObjectAnimator.ofFloat(this, "TranslationX", 0, -SizeUtils.dp2px(250));
        animator.setInterpolator(new LinearInterpolator());
        animator.setDuration(200);
        animator.start();
    }

    @Override
    public void reAnim() {
        ObjectAnimator animator = ObjectAnimator.ofFloat(this, "TranslationX", 0, 0);
        animator.start();
    }

    private ImageView mIconIv;
    private NumView mNumView;

    @Override
    public View onCreateView(GiftBean bean) {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.view_gift_def, this);
        mIconIv = view.findViewById(R.id.view_gift_icon);
        mIconIv.setImageResource(bean.imgRes);
        mNumView = view.findViewById(R.id.view_gift_num_view);
        mNumView.showNum(0);
        return view;
    }

    @Override
    public void onRunning(GiftRunStage stage) {
        switch (stage) {
            case IN:
                inAnim();
                break;
            case OUT:
                outAnim();
                break;
            case LOADING:
                break;
            case ADD:
                mNumView.showNumAdd();
                break;
        }
    }

    @Override
    public void onDestroy() {

    }
}
